package com.adlotto2.lcdns.cronos.parser;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.adlotto2.lcdns.cronos.data.CNLottoAdChangeListData;
import com.adlotto2.lcdns.cronos.datahandler.CNBaseDataParser;
import com.adlotto2.lcdns.cronos.datahandler.CNResultSet;
import com.adlotto2.lcdns.util.CNCronosLog;

public class CNLottoChangeListParser extends CNBaseDataParser{
	protected void onParseContent(Element xmlObject, CNResultSet resultSet)
			throws Exception {
		
		NodeList nodeList = xmlObject.getElementsByTagName("transfer");
		
		NodeList nodeAskDate = xmlObject.getElementsByTagName("transferReportingDate");
		NodeList nodePaidDate = xmlObject.getElementsByTagName("transferHandlingDate");
		NodeList nodeAskMoney = xmlObject.getElementsByTagName("askMoney");
		NodeList nodeIsTransfer = xmlObject.getElementsByTagName("isTransfer");
		NodeList nodeAccountName = xmlObject.getElementsByTagName("accountName");
		NodeList nodeBankName = xmlObject.getElementsByTagName("bankName");
		NodeList nodeAccountNumber = xmlObject.getElementsByTagName("accountNumber");
		NodeList nodeComment = xmlObject.getElementsByTagName("comment");
				
		NodeList totalCntNode = xmlObject.getElementsByTagName("totalCount");
		String totalCnt = totalCntNode.item(0).getFirstChild().getNodeValue();
		resultSet.setTotalCount(Integer.parseInt(totalCnt));
		
		int count = nodeList.getLength();
		CNCronosLog.d("count =============> " + count);
		
		for (int i = 0; i < count; i++)
		{
			Element elementData = (Element) nodeList.item(i);
			if (elementData == null)
				continue;
			
			CNLottoAdChangeListData dataSet = new CNLottoAdChangeListData();
			
			if(nodeAskDate.item(i).getFirstChild() != null)
				dataSet.askDate = nodeAskDate.item(i).getFirstChild().getNodeValue();
			
			if(nodePaidDate.item(i).getFirstChild() != null)
				dataSet.paidDate = nodePaidDate.item(i).getFirstChild().getNodeValue();
			
			if(nodeAskMoney.item(i).getFirstChild() != null)
				dataSet.askMoney = nodeAskMoney.item(i).getFirstChild().getNodeValue();
			
			if(nodeIsTransfer.item(i).getFirstChild() != null)
				dataSet.isChange = nodeIsTransfer.item(i).getFirstChild().getNodeValue();
			
			if(nodeAccountName.item(i).getFirstChild() != null)
				dataSet.accountName = nodeAccountName.item(i).getFirstChild().getNodeValue();
			
			if(nodeBankName.item(i).getFirstChild() != null)
				dataSet.bankName = nodeBankName.item(i).getFirstChild().getNodeValue();
			
			if(nodeAccountNumber.item(i).getFirstChild() != null)
				dataSet.accountNumber = nodeAccountNumber.item(i).getFirstChild().getNodeValue();
			
			if(nodeComment.item(i).getFirstChild() != null)
				dataSet.comment = nodeComment.item(i).getFirstChild().getNodeValue();
			
			resultSet.addDataSet(dataSet);
		}
	}
}
